package org.mixed.core.resource.info;

import lombok.Getter;
import lombok.Setter;
import org.mixed.core.domain.BaseDefinition;
import org.mixed.core.domain.api.Header;
import org.mixed.core.domain.api.Option;
import org.mixed.core.domain.api.Parameter;
import org.mixed.core.domain.api.Path;
import org.mixed.core.resource.Info;

import java.util.*;

@Getter
@Setter
public class ApiInfo extends Info {

	private String method = "GET";
	private List<Parameter> parameters = Collections.emptyList();
	private List<Option> options = new ArrayList<>();
	private String requestBody;
	private List<Header> headers = Collections.emptyList();
	private List<Path> paths = Collections.emptyList();
	private String responseBody;
	private String description;
	private BaseDefinition requestBodyDefinition;
	private BaseDefinition responseBodyDefinition;

//	public Map<String, String> options() {
//		Map<String, String> map = this.options.stream()
//				.collect(Collectors.toMap(BaseDefinition::getName, it -> String.valueOf(it.getValue()), (o, n) -> n));
//		MagicConfiguration.getMagicResourceService().getGroupsByFileId(this.id)
//				.stream()
//				.flatMap(it -> it.getOptions().stream())
//				.forEach(option -> {
//					if (!map.containsKey(option.getName())) {
//						map.put(option.getName(), String.valueOf(option.getValue()));
//					}
//				});
//		return map;
//	}

	// 兼容1.x处理。
	public void setOptionMap(Map<String, Object> optionMap) {

	}



	public void setOption(String json) {
//		this.options = JsonUtils.readValue(Objects.toString(json, "[]"), new TypeReference<List<Option>>() {
//		});
	}

//	public String getOptionValue(Options options) {
//		return getOptionValue(options.getValue());
//	}

//	public String getOptionValue(String key) {
//		return this.options.stream()
//				.filter(it -> key.equals(it.getName()))
//				.findFirst()
//				.map(it -> Objects.toString(it.getValue(), null))
//				.orElseGet(() -> MagicConfiguration.getMagicResourceService().getGroupsByFileId(this.id)
//						.stream()
//						.flatMap(it -> it.getOptions().stream())
//						.filter(it -> key.equals(it.getName()))
//						.findFirst()
//						.map(it -> Objects.toString(it.getValue(), null)).orElse(null)
//				);
//
//	}
}
